package com.toobigtofail.entities
{
	import fabulaexmachina.box2fp.Box2DEntity;
	
	import Box2D.Dynamics.b2Body;
	
	import com.toobigtofail.shapes.IShape;
	
	public class Obstacle extends Box2DEntity
	{
		public static const TYPE:String = "obstacle";
		
		private var _initOptions:Object;
		private var _shape:IShape;
		
		public function Obstacle(shape:IShape, angle:Number=0)
		{
			_shape = shape;
			
			super(shape.X, shape.Y, shape.Width, shape.Height, b2Body.b2_staticBody);
			
			type = TYPE;
			_initOptions = {angle: angle};
		}
		
		override public function added():void {
			super.added();
			
			_shape.buildShape(body);
			this.angle = _initOptions.angle;
		}
		
		public function serialize():XML {
			var o:XML = <obstacle/>;
			o.@angle = _initOptions.angle;
			
			o.appendChild(_shape.serialize());
			
			return o;
		}
	}
}